1 // Copyright (C) 2024 Rubén Beltrán del Río
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see https://map.tranquil.systems.
17 struct MapAxes: View {
20 let lineWidth: CGFloat
23 let stageHeight = CGFloat(100.0)
24 let padding = CGFloat(5.0)
27 ZStack(alignment: .topLeading) {
31 path.move(to: CGPoint(x: 0, y: 0))
32 path.addLine(to: CGPoint(x: 0, y: mapSize.height))
33 path.addLine(to: CGPoint(x: mapSize.width, y: mapSize.height))
34 path.move(to: CGPoint(x: mapSize.width, y: mapSize.height))
36 }.stroke(Color.Map.axisColor, lineWidth: lineWidth * 2)
39 Text("Visible").font(.Theme.axisLabel).foregroundColor(.Map.labelColor).rotationEffect(
42 .offset(CGSize(width: -35.0, height: 0.0))
43 Text("Invisible").font(.Theme.axisLabel).foregroundColor(.Map.labelColor).rotationEffect(
46 .offset(CGSize(width: -40.0, height: mapSize.height - 20))
51 .font(.Theme.axisLabel)
52 .foregroundColor(.Map.labelColor)
53 .frame(width: mapSize.width / 4, height: stageHeight / 2.0, alignment: .topLeading)
54 .offset(CGSize(width: 0.0, height: -stageHeight / 4.0))
55 Text("Industrialised")
56 .font(.Theme.axisLabel)
57 .foregroundColor(.Map.labelColor)
58 .frame(width: mapSize.width / 4, height: stageHeight / 2.0, alignment: .topLeading)
59 .offset(CGSize(width: mapSize.width - 100.0, height: -stageHeight / 4.0))
62 .font(.Theme.axisLabel)
63 .foregroundColor(.Map.labelColor)
64 .frame(width: w(stages[0]), height: stageHeight, alignment: .topLeading)
65 .offset(CGSize(width: 0.0, height: mapSize.height + padding))
68 .font(.Theme.axisLabel)
69 .foregroundColor(.Map.labelColor)
70 .frame(width: w(stages[1]) - w(stages[0]), height: stageHeight, alignment: .topLeading)
71 .offset(CGSize(width: w(stages[0]), height: mapSize.height + padding))
74 .font(.Theme.axisLabel)
75 .foregroundColor(.Map.labelColor)
76 .frame(width: w(stages[2]) - w(stages[1]), height: stageHeight, alignment: .topLeading)
77 .offset(CGSize(width: w(stages[1]), height: mapSize.height + padding))
80 .font(.Theme.axisLabel)
81 .foregroundColor(.Map.labelColor)
82 .frame(width: mapSize.width - w(stages[2]), height: stageHeight, alignment: .topLeading)
83 .offset(CGSize(width: w(stages[2]), height: mapSize.height + padding))
87 func w(_ dimension: CGFloat) -> CGFloat {
88 max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
94 mapSize: CGSize(width: 200.0, height: 200.0), lineWidth: CGFloat(1.0),
95 evolution: Stage.stages(.general), stages: [25.0, 50.0, 75.0]